﻿package top.college.cjh;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import model.AdminVO;
import model.DepartVO;
import model.SubjectVO;

public class Admin_Sub_Vedit extends JPanel{
	
	private Admin_Select as;
	private static SubjectVO pass = new SubjectVO();
			
		
	
	public Admin_Sub_Vedit () {

		setLayout( new BorderLayout( 0, 0) );
		adminTop();
		JScrollPane chart = new JScrollPane();
		add( chart, BorderLayout.CENTER );
		
		
		
		
		final DefaultTableModel model = new DefaultTableModel(){
				@Override
				public boolean isCellEditable(int row, int column) {
		
					return false;
				}
			
		};
		
		
		
		String title[]= { "순 번", "과목 번호",  "과목 이름","과목 유형", "과목 소개", "배정 학점", "담당 교수", "등록일" };
		model.setColumnIdentifiers( title );
		
		
		
		
		for ( SubjectVO s : as.selectSub() ){
			String tr =	s.getSub_tr();
			String no = s.getSub_no();
			String type = s.getSub_type_no();
			String name = s.getSub_name();			
			String info = s.getSub_info();
			String gd = s.getSub_point();
			String prof = s.getProf_no();
			String date = s.getReg_date();
			
			model.addRow( new String[]{ tr, no, name, type, info, gd, prof, date });
			
		}
		  
		
		
		
		
		JTable departTable = new JTable();
		departTable.addMouseListener( new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				if ( e.getClickCount() == 2 ){
					JTable departTable = (JTable) e.getSource();
					int row = departTable.getSelectedRow();//선택행+
					pass.setSub_tr( (String) model.getValueAt(row, 0) ) ;
					pass.setSub_no( (String) model.getValueAt(row, 1) ) ;
					pass.setSub_type_no( (String) model.getValueAt(row, 2) ) ;
					pass.setSub_name( (String) model.getValueAt(row, 3) ) ;
					pass.setSub_info( (String) model.getValueAt(row, 4) ) ;
					pass.setSub_point( (String) model.getValueAt(row, 5) ) ;
					pass.setProf_no( (String) model.getValueAt(row, 6) ) ;
					pass.setReg_date( (String) model.getValueAt(row, 7) ) ;
					// int col = table.getSelectedColumn();		// 선택열
					// String val = (String) table.getValueAt(row, col);
					// String msg = row + "/" + col + "/" + val + "\n" + "더브루 클릭크";
					// String msg = row + ""; // + "/" + col + "/" + val + "\n" + "더브루 클릭크";
				
					new Admin_Sub_Dial( pass );
					// 체크박스 트루펄스
					
				
				}
								
			//	super.mouseClicked(e);
			}
			
		});
		
		
		departTable.setModel(model);
		
		
				
		chart.setViewportView(departTable);
		
		setVisible( true );
		
		
	}
	
	
	private void adminTop(){
		
		JPanel top = new JPanel();
		
		JTextField serch = new JTextField();
		serch.setColumns( 30 );
		top.add( serch );	
		
		JButton see = new JButton();
		see.setText( "검 색" );
		
		JButton create = new JButton();
		create.setText( "추 가 등 록" );
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
		
			//	AdminVO v = new AdminVO();
				new Admin_Apend_Sub();
				
				
			}

		});
		
		top.add( see );		
		 top.add( create );
		add(  top, BorderLayout.NORTH );
		
		
	} // adminTop
	
		
		
		
		
}
